<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path;
%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
<title>功能室审批-云校通</title>
<jsp:include page="/WEB-INF/page/common/_header.jsp"></jsp:include>
</head>
<body ontouchstart style="background: #fff;">
	<div class="weui_tab tab-bottom">
		<div class="weui_tab_bd">
	        <div class="weui_tab kcfd-list1" id="tab4">
	            <div class="weui_navbar">
	                <div class="weui_navbar_item">
	                    	我申请的
	                </div>
	                <div class="weui_navbar_item" id="ccList">
	                    	已审批的
	                </div>
	                
	            </div>
	            <div class="weui_tab_bd">
	                
		            <div class="weui_panel weui_tab_bd_item qingjia mt0">
			            <div class="weui_panel_bd" id="myApply">
			                
			            </div>
			            <div class="dropload-down">
						    <div class="loadData dropload-hasData">点击加载更多数据...</div>
						</div>
		            </div>
			        
		            <div class="weui_panel weui_tab_bd_item qingjia mt0">
			            <div class="weui_panel_bd" id="ccMy">
			                
			            </div>
			            <div class="dropload-down">
						    <div class="loadData dropload-hasData">点击加载更多数据...</div>
						</div>
		            </div>
	            </div>
	        </div>
	        <a href="<%=basePath %>/ls/function/room/apply" class="weui_grid js_grid">
		       <div class="addBtnnew">
					<div class="linea"></div>
					<div class="lineb"></div>
		       </div>
		    </a>
		    <a href="<%=basePath %>/ls/function/room/successList" class="weui_grid js_grid">
			    <div class="room_zy" style="top: 60%;">
					已占用
		        </div>
	        </a>
		</div>
	</div>
	<jsp:include page="/WEB-INF/page/common/_footer.jsp"></jsp:include>
	<script>
		var isLoadccList = false;
		var myPage = 1,myRows = 5,ccPage = 1, ccRows = 5;
		$(function() {
			$('#tab4').tab({
				defaultIndex: 0,
				activeClass: "tab-blue "
			});
			$("#ccList").click(function() {
				if(!isLoadccList){
					loadccList();
				}
			})
			$(".dropload-down").on("click", ".dropload-hasData", function() {
				var id = $(this).closest(".weui_tab_bd_item").find(".weui_panel_bd").attr("id");
				var param = {
					page: id == 'myApply' ? myPage : ccPage,
					rows: id == 'myApply' ? myRows : ccRows
				}
				param.userType = 1
				if(id == 'myApply') {
					myPage+=1;
					param.applyerId = "${user.teacher.id}";
					param.applyType = 1
				}else {
					ccPage+=1;
					param.applyType = 2
				}
				loadItem(param, id);
			})
			var param = {
				page: myPage,
				rows: myRows,
				applyerId: "${user.teacher.id}",
				applyType: 1,
				userType: 1
			}
			myPage+=1;
			loadItem(param,"myApply");
		});
		function loadccList(){
			isLoadccList = true;
			var param = {
				page: ccPage,
				rows: ccRows,
				applyerId: "${user.teacher.id}",
				applyType: 2,
				userType: 1
			}
			ccPage += 1;
			loadItem(param, "ccMy");
		}
		function loadItem(param, id) {
			$.ajax({
				url: basePath + '/ls/function/room/page/query',
				type: 'post',
				dataType: 'json',
				data: param,
				success: function(data) {
					var html = "";
					if(data.data.rows.length == 0 || param.page*param.rows >= data.data.total) {// 如果没有数据
	            		 $("#" + id).closest(".weui_tab_bd_item").find('.loadData').removeClass("dropload-hasData").addClass("dropload-noData").html("没有更多数据了");
	                }
					for(var i in data.data.rows) {
						var itm = data.data.rows[i];
						html += '<a class="weui_cell weui_media_box weui_media_text" href="<%=basePath%>/ls/function/room/detail/'+itm.id+'">\
							<div class="weui_cell_bd weui_cell_primary">\
								<h4 class="weui_media_title">申请人：'+itm.applyer+'</h4>\
								<p class="weui_media_desc">'+itm.useReason+'</p>\
								<p class="weui_media_desc mt10">状态：'+itm.statusText+'</p>\
								<p class="weui_media_desc mt10">申请时间：'+getTime(itm.useDate, "yyyy年MM月dd日")+'</p>\
							</div>\
							<span class="weui_cell_ft"></span>\
						</a>';
					}
					$("#" + id).append(html);
				}
			});
		}
		function revoked(applyId) {
			$.confirm("您确定要撤销审批申请吗?","", function() {
				$.ajax({
					url: basePath + '/ls/work/approval/revoked',
					type: 'post',
					dataType: 'json',
					data: {
						applyId: applyId
					},
					success: function(data) {
						if(data.code == '000') {
							$.toast("撤销成功");
						}else {
							$.toast(data.msg, "cancel");
						}
						setTimeout(function() {
	            			window.location.href = window.location.href+"?v="+new Date().getTime();
	            		}, 1000);
					},
		            error: function(xhr, type){
		            	$.toptips("系统异常");
		            }
				});
            }, function() {
            });
		}
	</script>
</body>
</html>